﻿<UserControl x:Class="Projecturo.ProjecturoClient.View.UserManagementView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:tk="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:ext="clr-namespace:Projecturo.ProjecturoClient.Extension"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:model="clr-namespace:Projecturo.Model;assembly=Projecturo.Model"
    Height="Auto" Width="Auto">
    
    <UserControl.Resources>
        <ObjectDataProvider x:Key="UserRolesProvider" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type Type="{x:Type model:UserRoles}"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <DataTemplate DataType="{x:Type model:Project}">
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </UserControl.Resources>
    
    <DockPanel LastChildFill="True">
        <tk:DataGrid x:Name="UserList" ItemsSource="{Binding Users}" DockPanel.Dock="Top" AutoGenerateColumns="False" SelectedItem="{Binding SelectedUser}" MaxHeight="150" MinHeight="150" >
            <tk:DataGrid.Columns>
                <tk:DataGridTextColumn Binding="{Binding Id}" Header="Id" IsReadOnly="True"/>
                <tk:DataGridTextColumn Binding="{Binding Username}" Header="Username" IsReadOnly="True"/>
                <tk:DataGridTextColumn Binding="{Binding FirstName}" Header="First Name" IsReadOnly="True"/>
                <tk:DataGridTextColumn Binding="{Binding LastName}" Header="Last Name" IsReadOnly="True"/>
                <tk:DataGridTextColumn Binding="{Binding ShortName}" Header="Short Name" IsReadOnly="True"/>
            </tk:DataGrid.Columns>
        </tk:DataGrid>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
            <Button Content="New" Command="{Binding NewUserCommand}"/>
            <Button Content="Save" Command="{Binding SaveUserCommand}"/>
            <Button Content="Delete" Command="{Binding DeleteUserCommand}"/>
        </StackPanel>
        <GroupBox Header="User-Project Mapping" DockPanel.Dock="Right">
            <StackPanel>
                <ListBox x:Name="AllProjectsList" ItemsSource="{Binding AllProjects}" MaxHeight="150" MinHeight="150" SelectedItem="{Binding SelectedProject}"/>
                <StackPanel Orientation="Horizontal">
                    <Button Content="Add" Command="{Binding AddProjectCommand}" CommandParameter="{Binding SelectedUser.Projects}"/>
                    <Button Content="Remove" Command="{Binding RemoveProjectCommand}" CommandParameter="{Binding SelectedUser.Projects}"/>
                </StackPanel>
                <ListBox x:Name="UsersProjectList" ItemsSource="{Binding SelectedUser.Projects}" MaxHeight="150" MinHeight="150" SelectedItem="{Binding SelectedUserProject}"/>
            </StackPanel>
        </GroupBox>
        <GroupBox Header="Userdata">
            <StackPanel>
                <TextBlock Text="Id"/>
                <TextBlock Text="{Binding Path=SelectedUser.Id}"/>
                <TextBlock Text="Username"/>
                <TextBox Text="{Binding Path=SelectedUser.Username}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="Password"/>
                <PasswordBox ext:PasswordBoxBinding.BindPassword="true" ext:PasswordBoxBinding.BoundPassword="{Binding Path=SelectedUser.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="First Name"/>
                <TextBox Text="{Binding Path=SelectedUser.FirstName}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="Last Name"/>
                <TextBox Text="{Binding Path=SelectedUser.LastName}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="ShortName"/>
                <TextBox Text="{Binding Path=SelectedUser.ShortName}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="User Role"/>
                <ComboBox SelectedItem="{Binding Path=SelectedUser.Role}" ItemsSource="{Binding Source={StaticResource UserRolesProvider}}" IsEnabled="{Binding Path=IsReadOnly}"/>
                <TextBlock Text="Active"/>
                <CheckBox IsChecked="{Binding SelectedUser.IsActive}" IsEnabled="{Binding Path=IsReadOnly}"/>
            </StackPanel>
        </GroupBox> 
    </DockPanel>
</UserControl>
